home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / proff.zoo / pxlex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-04  |  3.3 KB  |  188 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <ctype.h>
  4. #include "proff.h"
  5.  
  6. /* translation table for control chars */
  7.  
  8. char c_ctrl[] = { 
  9.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  10.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  11.         0,  0,  0,  0,  0,  0,  0,  0,
  12.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  13.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  14.         0,  0,  0,  0,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
  15.         10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  16.         23, 25, 26, 27, 28, 29, 30, 31, 0,  1,  2,  3,  4,  5,
  17.         6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  18.         20, 21, 22, 23, 24, 25, 26, 0,  0,  0,  0,  0
  19.         };
  20.  
  21. /*
  22.  * getval - evaluate optional numeric argument
  23.  *
  24.  * increments i
  25.  */
  26. int
  27. getval(buf,i,argtyp)
  28. char buf[];
  29. int *i;
  30. int *argtyp;
  31. {
  32.     int j,k;
  33.  
  34.     j = *i;
  35.     k = *argtyp;
  36.  
  37.     skipbl(buf, &j);
  38.     k = buf[j];
  39.     if (k == '+' || k == '-')
  40.         j++;
  41.     *i = j;
  42.     *argtyp = k;
  43.     return(ctoi(buf,i));
  44. }
  45.  
  46. /*
  47.  * getarg - get the next argument from the buffer
  48.  *
  49.  * return values:      -1 - no argument
  50.  *            n - number of chars in argument
  51.  *
  52.  * also handles quoted ("..") strings. If a quote is wanted
  53.  * in the string, use "" or \". quotes are stripped.
  54.  *
  55.  * argument delimiters: blank, tab or comma (,).
  56.  *
  57.  * increments i
  58.  *
  59.  */
  60. int
  61. getarg(buf,i,arg)
  62. char buf[];
  63. int *i;
  64. char arg[];
  65. {
  66.     int j,k;
  67.     register char ch;
  68.  
  69.     j = *i;
  70.  
  71.     k = -1;
  72.     skipbl(buf,&j);
  73.     if (buf[j] != '\0') {
  74.         k = 0;
  75.         if (buf[j] == '\"') {
  76.             j++;
  77.             while (buf[j] != '\0') {
  78.                 if (buf[j] == '\"') {
  79.                     if (buf[j+1] == '\"') {
  80.                         arg[k++] = '\"';
  81.                         j += 2;
  82.                     }
  83.                     else
  84.                         break;
  85.                 }
  86.                 arg[k++] = buf[j++];
  87.             }
  88.             arg[k] = '\0';
  89.             j++;            /* skip the quote */
  90.             /* peek next char */
  91.             if (isalnum(buf[j]))
  92.                 error("improper argument list.");
  93.             j++;            /* skip the delimeter */
  94.         }
  95.         else {
  96.             ch = buf[j];
  97.             while (ch != ' '&& 
  98.                 ch != '\t'     && 
  99.                 ch != ','     &&
  100.                 ch != '\r'     && 
  101.                 ch != '\n'     && 
  102.                 ch != '\0') {
  103.                 arg[k++] = buf[j++];
  104.                 ch = buf[j];
  105.             }
  106.             arg[k] = '\0';
  107.             if (ch != '\0')    /* if non-null delimiter, skip */
  108.                 j++;
  109.         }
  110.         *i = j;
  111.     }
  112.     return(k);
  113. }
  114.  
  115. /*
  116.  * getpstr - get a special string to print out
  117.  *
  118.  */
  119. getpstr(buf,out)
  120. register char *buf;
  121. register char *out;
  122. {
  123.     register int i;
  124.     register char c, cc;
  125.     register char *num;
  126.     char numbuf[9];
  127.  
  128.     while(*buf != '\n' && *buf != '\0') {
  129.         c = *buf;
  130.         switch(c) {
  131.         case ' ':
  132.         case '\t':
  133.             while (*buf == ' ' || *buf == '\t')
  134.                 buf++;    /* skip blanks */
  135.             break;
  136.         case '\\':
  137.             if (*(buf+1) != '\0') {
  138.                 *out++ = *(buf+1);
  139.                 buf += 2;
  140.             }
  141.             else
  142.                 buf++;
  143.             break;
  144.         case '^':
  145.             if ((cc = c_ctrl[*(buf+1)]) != 0)
  146.                 *out++ = cc;
  147.             buf += 2;
  148.             break;
  149.         case '\"':
  150.             buf++;    /* skip the quote */
  151.             while (*buf != '\0') {
  152.                 if (*buf != '\"')
  153.                     *out++ = *buf++;
  154.                 else if (*(buf+1) == '\"') {
  155.                         *out++ = '\"';
  156.                         buf += 2;
  157.                 }
  158.                 else
  159.                     break;
  160.             }
  161.             buf++;    /* skip the quote */
  162.             break;
  163.         case '0':
  164.         case '1':
  165.         case '2':
  166.         case '3':
  167.         case '4':
  168.         case '5':
  169.         case '6':
  170.         case '7':
  171.         case '8':
  172.         case '9':
  173.             num = numbuf;
  174.             while (isdigit(*buf))
  175.                 *num++ = *buf++;
  176.             *num = '\0';
  177.             if ((i = atoi(numbuf)) > 256)
  178.                 error("non-ascii char value in write string.");
  179.             else if (i > 0)        /* do not output null */
  180.                 *out++ = (char) i;
  181.             break;
  182.         default:
  183.             *out++ = *buf++;
  184.         }
  185.     }
  186.     *out = '\0';
  187. }
  188.